/**
 * @(#) ComponentInterface.java
 */

package cn.edu.sjtu.se.dslab.component.method;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import cn.edu.sjtu.se.dslab.auth.User;

@Entity
@Table(name = "component_interface")
public class ComponentInterface implements Serializable {
	public static final  String INTERFACE_TYPE_BUS_COM = "总线通信";
	
	public static final  String INTERFACE_TYPE_IO_COM = "IO通信";
	
	public static final  String INTERFACE_TYPE_CONTROL_RESPONSE = "控制响应";
	
	public static final  String INTERFACE_TYPE_INFO = "信息显示";
	
	public static final  String INTERFACE_TYPE_ELSE = "其他";
	
	private static final long serialVersionUID = 1L;
	private String description;

	private User owner;

	private String name;

	private long id;

	private String uri;

	private Set<InterfaceMethod> interfaceMethods;

	private Set<MethodComponent> components;

	private boolean deleted;
	
	/**
	 * 接口的类型：总线通信、控制响应、IO通信、信息显示、其他
	 */
	private String itype;
	
	@Column(name = "deleted", nullable = true)
	public boolean isDeleted() {
		return deleted;
	}
	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}
	

	public ComponentInterface() {
		super();
		this.deleted = false;
	}
	public ComponentInterface(String description, User owner, String name,
			long id, String uri, Set<InterfaceMethod> interfaceMethods,
			Set<MethodComponent> components) {
		super();
		this.description = description;
		this.owner = owner;
		this.name = name;
		this.id = id;
		this.uri = uri;
		this.interfaceMethods = interfaceMethods;
		this.components = components;
		this.deleted = false;
	}
	

	@Column(name = "description", nullable = true, length = 255)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "owner_id", nullable = true)
	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	@Column(name = "name", nullable = true, length = 255)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "uri", nullable = true, length = 255)
	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@OneToMany(cascade = { CascadeType.REFRESH,CascadeType.REMOVE }, mappedBy = "cInterface", fetch = FetchType.EAGER)
	public Set<InterfaceMethod> getInterfaceMethods() {
		return interfaceMethods;
	}

	public void setInterfaceMethods(Set<InterfaceMethod> interfaceMethods) {
		this.interfaceMethods = interfaceMethods;
	}

	@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "cinterface", fetch = FetchType.EAGER)
	public Set<MethodComponent> getComponents() {
		return components;
	}

	public void setComponents(Set<MethodComponent> components) {
		this.components = components;
	}
	
	
	@Column(name = "itype", nullable = true, length = 255)
	public String getItype() {
		return itype;
	}
	public void setItype(String itype) {
		this.itype = itype;
	}
}
